package C;

import java.util.Scanner;

class Node {
    int val;
    Node prev;
    Node next;

    public Node(int val) {
        this.val = val;
        this.prev = null;
        this.next = null;
    }
}

class CycleLinkedList{
    Node head;
    Node tail;
    int size;

    public CycleLinkedList() {
        this.head = null;
        this.tail = null;
        this.size = 0;
    }


    public void append(int val) {
        Node node = new Node(val);
        if (this.size>0) {
            this.tail.next = node;
            node.prev = this.tail;
            node.next = this.head;
            this.head.prev = node;
            this.tail = node;
        } else {
            this.head = this.tail = node;
            node.prev = node.next = node;
        }
        this.size++;
    }


    public Node remove(Node node) {
        Node next = node.next;
        Node prev = node.prev;
        prev.next = next;
        next.prev = prev;

        if (this.head == node){
            this.head = this.head.next;
        }
        if (this.tail == node){
            this.tail = this.tail.prev;
        }

        node.next = null;
        node.prev = null;

        this.size--;

        return next;
    }



}



public class C6My {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        CycleLinkedList cl = new CycleLinkedList();
        for (int i=1;i<=n;i++) {
            cl.append(i);
        }
        int num = 1;
        Node cur = cl.head;
        while(cl.size>1) {
            if(num == 3) {
                cur = cl.remove(cur);
                num = 1;
            } else {
                num++;
                cur = cur.next;
            }
        }
        System.out.println(cur.val);

    }




}
